package homework04;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class PersonTest {
    public static void main(String[] args) throws Exception{
        Class clz = Person.class;
        Person person = (Person) clz.getConstructor(String.class,int.class).newInstance("小明",18);
        Method setName = clz.getDeclaredMethod("setName", String.class);
        setName.invoke(person,"小红");

        Field age = clz.getDeclaredField("age");
        age.setAccessible(true);
        age.set(person,20);

    }
}
